<?php
session_start();
include_once 'conn.php';
$title = $_POST['title'];
$contents = $_POST['contents'];
$postTime = date("Y-m-d H:i:s");
$sql = "insert into maintopic (title, contents, userid, posttime, ip) values ('$title','$contents','".$_SESSION['userID']."','".$postTime."','')";
$result = mysqli_query($conn,$sql);
if($result){
    $a['error'] = 0;
    $a['username'] = $_SESSION['username'];
    $a['postTime'] = $postTime;
    $a['lastInsertID'] = mysqli_insert_id($conn);
}
else{
    $a['error'] = 1;
    $a['errMsg'] = mysqli_error($conn);
}
echo json_encode($a);